From d8dc06e63ab99fe2ed4a9b8b4df9e4818350525e Mon Sep 17 00:00:00 2001 From: robertl Date: Mon, 21 Feb 2011 16:55:33 +0000 Subject: [PATCH] Improve handling of bogus NMEA. git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4050 f51c46e8-681c-474f-0cfe-069cfd0219fb --- gpsbabel/nmea.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/gpsbabel/nmea.c b/gpsbabel/nmea.c index df3da62bd..a3bac09b5 100644 --- a/gpsbabel/nmea.c +++ b/gpsbabel/nmea.c @@ -532,8 +532,12 @@ gprmc_parse(char *ibuf) } /* Skip past nine commas in ibuf to reach the dmy value */ - for (dmybuf=ibuf,i=0; i<9 && dmybuf != NULL; i++) { + for (dmybuf=ibuf,i=0; i<9; i++) { dmybuf= strchr(dmybuf, ','); + if(dmybuf==NULL) { + /* If we run out of commas, the sentence is invalid. */ + return; + } dmybuf++; } @@ -910,6 +914,12 @@ nmea_parse_one_line(char *ibuf) had_checksum = 0; return; } + + if(strstr(tbuf+1,"$")!=NULL) + { + /* If line has more than one $, there is probably an error in it. */ + return; + } /* @@@ zmarties: The parse routines all assume all fields are present, but the NMEA format allows any field to be missed out if there is no data -- 2.30.2